import Mine from "../../../../facility/pulbicFacility/Mine";
import { FacilityType } from "../../../../info/GameEnum";
import { AiEnvironment } from "../../AiGameAction";
import { DecisionNode } from "../../DecisionTree";

export default class DecisionOil extends DecisionNode {

    environment: AiEnvironment & { lackCrystal: number, lackOil: number, lackAll: number };

    constructor(environment: any) {
        super(environment);
        this.childDecisionNodes.push(new BuildOilWell(environment));
    }

    /**
     * 对油矿的需求
     * @returns 
     */
    evaluate(): number {
        return this.environment.lackOil / this.environment.lackAll * 100;
    }

}

/**
 *  建造采油机
 */
class BuildOilWell extends DecisionNode {

    chooseOilMine: Mine

    /**
     * 唯一的选择
     * 只要能建造就放回100
     * @returns 
     */
    evaluate(): number {
        if (!this.environment.facilityFeasibility.get(FacilityType.采油机).every(i => i))
            return 0;

        let oilMines = this.environment.player.getOilMineByDomain();
        if (!oilMines.length) return 0;
        //选择余量最多的那个
        this.chooseOilMine = oilMines.reduce((max: Mine, curr: Mine) => curr.curCount > max.curCount ? curr : max, oilMines[0]);
        return 100;
    }

    execute(): number {
        this.environment.player.addFacility(FacilityType.采油机, this.chooseOilMine.locations);
        return 0;
    }

}

